package jmu.cultural_tourism.service.impl;

import jmu.cultural_tourism.entity.PostTag;
import jmu.cultural_tourism.dao.PostTagDao;
import jmu.cultural_tourism.service.PostTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import jakarta.annotation.Resource;

/**
 * 标签表(PostTag)表服务实现类
 *
 * @author makejava
 * @since 2025-07-17 15:33:09
 */
@Service("postTagService")
public class PostTagServiceImpl implements PostTagService {
    @Autowired
    private PostTagDao postTagDao;

    /**
     * 通过ID查询单条数据
     *
     * @param postTagId 主键
     * @return 实例对象
     */
    @Override
    public PostTag queryById(Integer postTagId) {
        return this.postTagDao.queryById(postTagId);
    }

    /**
     * 分页查询
     *
     * @param postTag     筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<PostTag> queryByPage(PostTag postTag, PageRequest pageRequest) {
        long total = this.postTagDao.count(postTag);
        return new PageImpl<>(this.postTagDao.queryAllByLimit(postTag, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param postTag 实例对象
     * @return 实例对象
     */
    @Override
    public PostTag insert(PostTag postTag) {
        this.postTagDao.insert(postTag);
        return postTag;
    }

    /**
     * 修改数据
     *
     * @param postTag 实例对象
     * @return 实例对象
     */
    @Override
    public PostTag update(PostTag postTag) {
        this.postTagDao.update(postTag);
        return this.queryById(postTag.getPostTagId());
    }

    /**
     * 通过主键删除数据
     *
     * @param postTagId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer postTagId) {
        return this.postTagDao.deleteById(postTagId) > 0;
    }
}
